package com.xbh.management.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xbh.management.entity.ManRoleVO;
import com.xbh.management.mapper.RoleMapper;
import com.xbh.management.model.ManMenu;
import com.xbh.management.model.ManRole;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.time.chrono.Era;

/**
 * @program: management-center
 * @description:
 * @author: 许宝华
 * @create: 2021-09-25 14:25
 */



@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper,ManRole> implements RoleService {

    /**
     *
     * @param page
     * @param role
     * @return
     */
    @Override
    public IPage<ManRole> queryAllRole(Page<ManRole> page, ManRole role) {

        LambdaQueryWrapper<ManRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ManRole::getDeleted,role.getDeleted())
                .like(StringUtils.isNotBlank(role.getRoleName()),ManRole::getRoleName,role.getRoleName());

        Page<ManRole> rolePage = this.baseMapper.selectPage(page, wrapper);
        return rolePage;
    }

    /**
     * 保存角色
     * @param role
     * @return
     */
    @Override
    public int saveRole(ManRole role) {
        return this.baseMapper.insert(role);
    }

    /**
     * 根据roleId查询角色
     * @param roleId
     * @return
     */
    @Override
    public ManRole queryRoleWithRoleId(Long roleId) {
        return this.baseMapper.selectById(roleId);
    }

    /**
     * 根据id修改角色
     * @param role
     * @return
     */
    @Override
    public int updateRoleWithRoleId(ManRole role) {
        return this.baseMapper.updateById(role);
    }


    /**
     * 查询当前角色所关联的用户
     * @param role
     * @return
     */
    @Override
    public ManRoleVO queryRoleRelationAllUser(ManRole role) {
        return this.baseMapper.queryRoleRelationAllUser(role);
    }



    @Override
    public ManRoleVO queryMenuBuRole(ManRole role) {
        return this.baseMapper.queryMenuBuRole(role);
    }


}
